using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace G2007.CodeGen.Library.Data
{
	/// <summary>
	/// Implemetation of CGObject allows us to have multiple object types in the system
	/// this is especially designed for the user of the INSTANCE as a new entry. 
	/// </summary>
	public abstract class CGObject
	{

        protected bool isNew = false;

        public bool IsNew { get { return isNew; } set { isNew = value; } }

		private bool isNested;

		public bool IsNested
		{
			get { return isNested; }
			set { isNested = value; }
		}
	

		protected bool isComposite = false;

		public bool IsComposite { get { return isComposite; } set { isComposite = value; } }

        public CGObject () { }

        public CGObject(string name, HeaderInfo hi, string[] data, 
			CGObject[] otherClasses, Enum[] enums, bool isComposite, string dbname, bool isNested ) 
		{
			this.name=name;
			this.hi=hi;
			this.enums=enums;
			this.isComposite = isComposite;
			
			this.data=data;
			this.otherClasses=otherClasses;

			this.isNested = isNested;

			this.dbname = dbname;
		}

		private string dbname;

		public string DBName
		{
			get { return dbname; }
			set { dbname = value; }
		}
	

		protected string name;
   

		public string Name { get { return name; } set { name = value; } }
        public string LName { get {


            

            string output = Name.Substring ( 0 , 1 ).ToLower ( );

            for ( int x = 1 ; x < Name.Length ; x++ )
            {
                if ( Name[ x ].ToString ( ).ToLower ( ) != Name[ x ].ToString ( ) )
                {
                    output += "_" + Name[ x ].ToString ( ).ToLower ( ) ;
                }
                else output += Name[ x ].ToString ( );
            }

            return output;
        } 
            
            
            set { } 
        
        
        }

		[XmlIgnore ()]
		protected string[] data;

		[XmlIgnore ()]
		public string[] Data { get { return data; } }


		[XmlIgnore ()]
		protected DeleteArray[] deleteArray;

		public DeleteArray[] DeleteArrayObjs
		{
			get { return deleteArray; }
			set { deleteArray = value; }
			
		}

		public ClassAttributes[] ClassAttribs
		{
			get { return classAttributes; }
			set { classAttributes = value; }
		}


		protected ClassAttributes[] classAttributes;

        protected ClassAttributes[] removedAttributes;

        public ClassAttributes[] RemovedAttributes { 
            get { return removedAttributes; } 
            set { removedAttributes = value; } 
        }


		[XmlIgnore ()]
		protected CGObject[] otherClasses;

		[XmlIgnore ()]
		public CGObject[] OtherClasses { get { return otherClasses; } set { } }

		[XmlIgnore ()]
		protected Enum[] enums;

		[XmlIgnore ()]
		public Enum[] Enums { get { return enums; } }

		protected HeaderInfo hi;

		public HeaderInfo @HeaderInfo { get { return hi; } set { hi=value; } }


		public bool GenerateFields ( out string error )
		{
			this.classAttributes = Helper.ExtractAttributes ( out error , this );
			return error.Length == 0;
		}
	}
}
